# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=scons
pkgver=4.7.0
pkgrel=1
pkgdesc="Software construction system"
url="https://scons.org/"
arch="noarch"
license="MIT"
depends="python3"
makedepends="py3-gpep517 py3-setuptools py3-wheel"
checkdepends="xz"
subpackages="$pkgname-pyc $pkgname-doc"
# fetching both sources, because only github tarball has tests
# and only sourceforge tarball has prebuilt manpages
# building the scons manpages requires working scons install...
source="https://github.com/SCons/scons/archive/$pkgver/scons-$pkgver.tar.gz
	https://downloads.sourceforge.net/project/scons/scons/$pkgver/SCons-$pkgver.tar.gz
	dont-install-manpages.patch
	"

# tests need py3-psutil from community
options="!check"

prepare() {
	default_prepare

	# remove failing test
	case $CARCH in
	ppc64le) rm test/builderrors.py ;;
	esac
}

build() {
	gpep517 build-wheel --wheel-dir .dist --output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 runtest.py -a
}

package() {
	python3 -m installer -d "$pkgdir" .dist/*.whl

	# find and remove directories containing docbook files
	find "$pkgdir" -name 'docbook' -type d -exec rm -rf {} +

	install -Dm644 \
		"$srcdir"/SCons-$pkgver/scons.1 \
		"$srcdir"/SCons-$pkgver/scons-time.1 \
		"$srcdir"/SCons-$pkgver/sconsign.1 \
		-t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
8be4d611c375c13467a1a437e0d47873f973584d9a1be0d1cbbd345685a8f477fc19fa59ab01bca1ab7be8af0034d5cfda360090ee4b347c41f7bfea363bfe6c  scons-4.7.0.tar.gz
d08fba3e7f058eb2eeee4a129d10b55affada6b192932f069271fcbc28fd8216b2bf7e94285d9c448235a3965a789d3a91db9ebae1945aa73306788009dd2e77  SCons-4.7.0.tar.gz
286dbd5230119237b2ef2ece572d70c8b22d78ac71c5ac7a7a23e1c8597ca6379f324293560276777b608eb7b7af070374e8df91b593e6c656d81e13367efccd  dont-install-manpages.patch
"
